﻿using UnityEngine;

namespace JH
{
    public static class ContainsExtension
    {
        /// <summary>
        ///  判断一个矩形是否包含另一个矩形
        /// </summary>
        ///  <param name="rectA">矩形A</param>
        ///  <param name="rectB">矩形B</param>
        /// <param name="cornerContains">四个角落是否被包含</param>
        /// <param name="camera">相机</param>
        public static bool ContainsEm(this RectTransform rectA, RectTransform rectB, out CornerBool cornerContains,
            Camera camera = null)
        {
            var rectAScreenBounds = rectA.GetScreenBoundsRectEm(camera);
            var rectBScreenBounds = rectB.GetScreenBoundsRectEm(camera);
            return rectAScreenBounds.ContainsEm(rectBScreenBounds, out cornerContains);
        }

        /// <summary>
        /// 是否存在重叠
        /// </summary>
        public static bool OverLapEm(this RectTransform rectA, RectTransform rectB, Camera camera = null)
        {
            var rectAScreenBounds = rectA.GetScreenBoundsRectEm(camera);
            var rectBScreenBounds = rectB.GetScreenBoundsRectEm(camera);
            return rectAScreenBounds.OverLapEm(rectBScreenBounds);
        }
    }
}